<?php
namespace app\exception;

use think\exception\Handle;
use think\Response;

use app\exception\ApiException;

class ExceptionHandler extends Handle
{
    public function render($request, \Throwable $e): Response
    {
        // 判断是否为Http异常
        if ($e instanceof ApiException) {
            // 返回json响应
            return json(['code' => $e->getMessageCode(), 'msg' => $e->getMessage(), 'data' => $e->getData()]);
        }
        // 其他异常交给系统处理
        return parent::render($request, $e);
    }
}
